package com.gimi.cloud.jimi.dao.dao.product;

import java.util.List;
import java.util.Map;

import com.gimi.cloud.jimi.dao.common.SqlProvider;
import com.gimi.cloud.jimi.dao.dao.sys.BaseDao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.gimi.cloud.jimi.dto.product.ProductSkuDto;
import com.gimi.cloud.jimi.entity.product.ProductSkuEntity;
import org.apache.ibatis.annotations.SelectProvider;

public interface ProductSkuDao extends BaseMapper<ProductSkuEntity>,BaseDao<ProductSkuEntity,ProductSkuDto> {
	
    int deleteByPrimaryKey(String skuId);

    int insert(ProductSkuEntity record);

    int insertSelective(ProductSkuEntity record);
    
    int insertSelectiveDto(ProductSkuDto record);

    ProductSkuEntity selectByPrimaryKey(String skuId);
    
    List<ProductSkuDto> selectByProdId(String prodId);

    int updateByPrimaryKeySelective(ProductSkuEntity record);

    int updateByPrimaryKey(ProductSkuEntity record);
    
    @Select("SELECT prod_status FROM ec_prod_status WHERE prod_id = #{prodId}")
	int getStatusById(@Param(value = "prodId") String prodId);

    /**
     * 查询上加单品的品类模板值id
     * @return
     */
    @Select("SELECT GROUP_CONCAT(eps.sku_value) FROM (select distinct sku_value from ec_prod_sku) eps")
    String selectModelValueInProduct();
    
    
    @Select("SELECT * FROM ec_prod_sku WHERE prod_id = #{prodId} AND sku_stock > 0")
    List<ProductSkuDto> selectByProdIdAndStock(String prodId);

    @Select("SELECT sku_id,model_value FROM ec_prod_sku sku LEFT JOIN ec_prod_cat_model_value cm ON FIND_IN_SET(cm_id,sku.sku_value) WHERE sku.sku_id IN (#{skuId});")
    List<Map> getModelValueBySkuIds(@Param(value = "skuId") String skuId);

    @SelectProvider(type = SqlProvider.class,method = "sql")
    List<Map> getModelValueBySkuIds2(@Param(value = "sql") String sql);
    
    @Select("SELECT model_value FROM ec_prod_sku sku LEFT JOIN ec_prod_cat_model_value cm ON FIND_IN_SET(cm_id,sku.sku_value) WHERE sku.sku_id = #{skuId}")
    List<String> getModelValueBySkuId(@Param(value = "skuId") String skuId);
    
    
}